/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package imageProcessing.classes;

import ProcesamientoImagenes.interfaces.ImageComposer;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 *
 * @author damfercer
 */
public class TransparencyOverlayComposer implements ImageComposer{
    private BufferedImage backgroundImage;
    private BufferedImage foregroundImage;
    private Float foregroundAlpha;
    
    public TransparencyOverlayComposer(BufferedImage backgroundImage, BufferedImage foregroundImage){
        this.backgroundImage=ImageHelper.getType4ByteABGRBufferedImage(backgroundImage);
        this.foregroundImage=ImageHelper.getType4ByteABGRBufferedImage(foregroundImage);
        this.foregroundAlpha=1.0f;
    }
    
    public TransparencyOverlayComposer(BufferedImage backgroundImage, BufferedImage foregroundImage, Float foregroundAlpha){
        this.backgroundImage=ImageHelper.getType4ByteABGRBufferedImage(backgroundImage);
        this.foregroundImage=ImageHelper.getType4ByteABGRBufferedImage(foregroundImage);
        this.foregroundAlpha=foregroundAlpha;
    }
    
    @Override
    public BufferedImage compose() {
        return compose(this.backgroundImage,this.foregroundImage);
    }

    @Override
    public BufferedImage compose(BufferedImage background, BufferedImage foreground) {
        BufferedImage resImage=ImageHelper.deepCopy(background);
        Graphics2D createGraphics = resImage.createGraphics();
        createGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,foregroundAlpha));
        createGraphics.drawImage(foreground, 0, 0, null);
        return resImage;
    }
    
}
